package com.j177.could.controller;

import com.j177.cloud.dto.MovieDto;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author:LuJiaHong
 * @Date:2020/11/30~17:52:42
 * @Version 1.0
 */
@RestController
public class MovieController {
    @GetMapping("price/{movieName}/{movieNum}")
    public Object price( @PathVariable String movieName, @PathVariable Integer movieNum){
        int a = -1;
        List<MovieDto> movieDtoList = MovieDto.movieDtoList;
        if(movieDtoList!=null){
            for(MovieDto m : movieDtoList){
                if(m.getMovieName().equals(movieName)){
                    a=1;
                    if(m.getMovieNums()>=movieNum){
                        m.setMovieNums(m.getMovieNums()-movieNum);
                        a=-1;
                        System.out.println("用户买的票是："+m.getMovieName()+";共买："+m.getMovieNums()+";总价格："+m.getMoviePrice()*movieNum+"$");
                        return "取票编码："+m.getMovieName()+System.currentTimeMillis()+"；总价格："+m.getMoviePrice()*movieNum+"$";
                    }else{
                        return "余票只有："+m.getMovieNums()+"张";
                    }
                }
            }
            if(a==-1){
                return "没有此种电影";
            }
        }else{
            return "当前影院无电影上影";
        }
        return "";
    }
}
